package us.icitap.commandcenter.ui.dispatcher;

import java.util.List;

import us.icitap.commandcenter.business.ejb.persistence.Call;
import us.icitap.commandcenter.ui.custom.CustColumnGenerator;
import us.icitap.commandcenter.ui.custom.CustTable;

import com.vaadin.data.util.BeanItemContainer;

public class ClosedVerificationTable extends CustTable{


	final BeanItemContainer<Call> beans  = new BeanItemContainer<Call>(Call.class);
			
	public ClosedVerificationTable(boolean oneDispatcher) {
	
		this.setContainerDataSource(beans);
		
		
		if(!oneDispatcher){
			this.setVisibleColumns(new Object[]{"caller","recordDate", "callReason", "address", "description","mainDispatcher", "verifiedCallReason", "verificationNotes", "uniqueNumber"});
			this.setColumnHeaders(new String[]{"TELEFONUESI", "DT. REGJ.", "ARSYEJA E TELEFONATES", "ADRESA", "PERSHKRIMI","Z. MBULIMIT", "REZULTATI I VERIFIKIMIT", "SHENIME", "NR. UNIK"});
			this.addGeneratedColumn("mainDispatcher", CustColumnGenerator.dispatcherColumnGenerator);
		}
		else{
			this.setVisibleColumns(new Object[]{"caller","recordDate", "callReason", "address", "description", "verifiedCallReason", "verificationNotes", "uniqueNumber"});
			this.setColumnHeaders(new String[]{"TELEFONUESI", "DT. REGJ.", "ARSYEJA E TELEFONATES", "ADRESA", "PERSHKRIMI", "REZULTATI I VERIFIKIMIT", "SHENIME", "NR. UNIK"});
		}
		
		this.addGeneratedColumn("callReason", CustColumnGenerator.callReasonColumnGenerator);
		this.addGeneratedColumn("verifiedCallReason", CustColumnGenerator.callReasonColumnGenerator);
		this.addGeneratedColumn("verificationNotes", CustColumnGenerator.htmlColumnGenerator);
		this.addGeneratedColumn("uniqueNumber", CustColumnGenerator.uniqueNumberColumnGenerator);
		
		
		
		this.setSelectable(true);  
		this.setColumnCollapsingAllowed(true);
		this.setColumnCollapsed("caller", true);
		this.setColumnCollapsed("callReason", true);
		
		this.setPageLength(10);
		this.setWidth("100%");
		this.setColumnWidth("callReason", 100);
		this.setColumnWidth("address", 200);
		this.setColumnWidth("description", 200);
	
		this.updateTable();

		this.addStyleName("green");
	}
	
	
	
	public void updateTable(){
		boolean[] order = {false};
		this.sort(new Object[]{"recordDate"}, order);
		this.setCaption("Totali i telefonatave me status TE VERIFIKUARA: " + beans.size());
	}
	
	public void addCallToTable(Call call){
		beans.addBean(call);
		this.updateTable();
	}
	public void addCallToTable(List<Call> callList){
		beans.addAll(callList);
		this.updateTable();
	}
	
	public void updateCall(Call call){
		beans.removeItem(call);
		beans.addBean(call);
		boolean[] order = {false};
		this.sort(new Object[]{"recordDate"}, order);
	}
	
	
	
}
